package holdem.workingMemory;

import holdem.*;

//~--- imports: JDK -----------------------------------------------------------

import java.util.*;

/**
 *
 * @author Pai Qi
 * @author qipai0@gmail.com
 * Description: Only one workingMemory is allowed to exist.
 *
 */

public class WorkingMemory extends NestedIntegerList {
    //INVARIANCE: The order of fields (including static) should not be changed

    public static final WorkingMemory me;

    static {
	me = new WorkingMemory();
        me.init();
    }

    //~--- fields & initializers ----------------------------------------------

    public List<Player>      playingOrder;
    public List<Card> tableCards;
    public Integer potMoney;
    public Integer currentPhase;
    // currentPhase == table card counts (possible value: 0,3,4,5)
    public Integer currentSmallBlind;
    public Integer currentBigBlind;
    public Integer currentDealerID = 0;

    //~--- constructors -------------------------------------------------------

    private WorkingMemory() {}

    public static WorkingMemory get() {
        return me;
    }

    /**
     * Reset the working memory
     */
    public void init() {
        if(tableCards == null) {
            tableCards = new ArrayList<Card>();
        } else {
            tableCards.clear();
        }
        if(playingOrder == null) {
            playingOrder = new ArrayList<Player>();
        } else {
            playingOrder.clear();
        }

        potMoney = 0;
        currentPhase = 0;
        currentSmallBlind = 0;
        currentBigBlind = 0;
    }

    public void clear() {
        if(tableCards == null) {
            tableCards = new ArrayList<Card>();
        } else {
            tableCards.clear();
        }

        potMoney = 0;
        currentPhase = 0;
    }

}
